1 module firecracker_d.models.drive;
2 import firecracker_d.models.rate_limiter;
3 import firecracker_d.models.base_model;
4 
5 struct Drive {
6 	mixin BaseModel;
7 
8 	@serializationRequired @serializationKeys("drive_id") string driveID;
9 
10 	/***
11 	* Required: bool representing if the disk will be read-only
12 	***/
13 	@serializationRequired @serializationKeys("is_read_only") bool isReadOnly;
14 
15 	/***
16 	* Required: bool representing if the disk will be mounted as the root partition
17 	***/
18     @serializationRequired 
19 	@serializationKeys("is_root_device") bool isRootDevice;
20 
21 	/***
22 	* Represents the unique ID of the boot partition
23 	*
24 	* Only used if `isRootDevice == true`
25 	***/
26 	@serializationKeys("partuuid") string partUUID;
27 
28 	/***
29 	* Required: Path to drive on the host's file system
30 	***/
31 	@serializationRequired 
32     @serializationKeys("path_on_host") string pathOnHost;
33 
34 	/***
35 	* Ratelimiter. Intended to stop a user from
36 	* thrashing our disk, as well as keeping the microVM under
37 	* control.
38 	***/
39 	@serializationKeys("rate_limiter") RateLimiter rateLimiter; 
40 
41 	/***
42 	* Create the drive via the Firecracker API. 
43     * Throws: FirecrackerException on error.
44 	***/
45 	bool put(FirecrackerAPIClient cl) {
46 		Response r = cl.put("/drives/" ~ driveID, this.stringify);
47 
48 		if(r.code == 204) {
49 			return true;
50 		}
51 		else {
52 			throwFromResponse(r);
53 			return false;
54 		}
55 			
56 	}
57 }
58 
59 /*** 
60 * Used to update drive information after microvm start?
61 ***/
62 struct PartialDrive {
63 	mixin BaseModel;
64     /***
65     * Firecracker ID for drive
66     ***/
67     @serializationRequired
68 	@serializationKeys("drive_id") string driveID;
69 
70     /***
71     * Host level path for guest drive
72     ***/
73     @serializationRequired
74 	@serializationKeys("path_on_host") string pathOnHost;
75 
76 	/***
77 	* Modify the drive via the Firecracker API
78     * Post-boot only
79     * Throws: FirecrackerException
80 	***/
81 	bool patch(FirecrackerAPIClient cl) {
82 		Response r = cl.patch("/drives/" ~ driveID, this.stringify);
83 		if(r.code == 204) {
84 			return true;
85 		}
86 		else {
87 			throwFromResponse(r);
88 			return false;
89 		}
90 	}
91 
92 }